#ifndef _COMMON_QUEUE_H_
#define _COMMON_QUEUE_H_

#include "mutex.h"

#include <deque>
using namespace std;

template< typename T, typename Deque = deque<T> >
class CQueue
{
public:

    size_t Size()
    {
        size_t size;

        m_lock.Lock();
        size = m_queue.size();
        m_lock.Unlock();

        return size;
    }

    int Push(const T& x)
    {
        m_lock.Lock();
        m_queue.push_back(x);
        m_lock.Unlock();

        return 0;
    }

    int Pop(T &x)
    {
        int result = -1;

        m_lock.Lock();
        if(!m_queue.empty())
        {
            x = m_queue.front();
            m_queue.pop_front();

            result = 0;
        }
        m_lock.Unlock();

        return result;
    }

    int Front(T &x)
    {
        int result = -1;

        m_lock.Lock();
        if(!m_queue.empty())
        {
            x = m_queue.front();

            result = 0;
        }
        m_lock.Unlock();

        return result;
    }

private:

    Deque  m_queue;
    CMutex m_lock;
};

#endif //_COMMON_QUEUE_H_
